{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>
            <a href="javascript:location.reload()"> <i title="刷新" class="layui-icon layui-icon-refresh-3 child-page-refresh"></i></a>
            联系方式配置
        </legend>
    </fieldset>
    <form class="layui-form layui-form-pane" lay-filter="form-contact">
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-4">
                <input type="text" name="phone" lay-verify=""  placeholder="电话" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">官网</label>
            <div class="layui-input-4">
                <input type="text" name="web" lay-verify=""  placeholder="官网" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">微博</label>
            <div class="layui-input-4">
                <input type="text" name="weibo" lay-verify="" placeholder="微博" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小红书</label>
            <div class="layui-input-4">
                <input type="text" name="redbook" lay-verify="" placeholder="小红书" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">二维码url</label>
            <div class="layui-input-4">
                <input type="hidden" name="qrcode" id="qrcode" lay-verify="required" placeholder="二维码地址" value="" class="layui-input">
                <!-- <div class="layui-input-block"> -->
                    <div class="layui-upload" style="padding-left: 10px;">
                        <button type="button" class="layui-btn layui-btn-primary" id="adBtn"><i class="icon icon-upload3"></i>点击上传</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="adPic" src="{$baseInfo.qrcode}">
                            <p id="demoText"></p>
                        </div>
                    </div>
                <!-- </div> -->
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <!-- <button type="reset" class="layui-btn layui-btn-primary">{:lang('reset')}</button> -->
                <a href="{:url('contactList')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script>
    layui.use(['form', 'layer','upload'], function () {
        var form = layui.form,layer = layui.layer,$= layui.jquery,upload = layui.upload;
        //发送测试邮件
        form.val("form-contact", {$info|raw})
        
        //提交监听
        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            data.field.inc_type = '{$inc_type}';
            $.post("{:url('system/contact')}",data.field,function(res){
                layer.close(loading);
                if(res.code > 0){
                    layer.msg(res.msg,{icon: 1, time: 1000},function(){
                        location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg,{icon: 2, time: 1000});
                }
            });
        })

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#adBtn'
            ,url: '{:url("UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#adPic').attr('src', result); //图片链接（base64）
                });
            },
            done: function(res){
                if(res.code>0){
                    $('#qrcode').val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    })
</script>
</body>
</html>